package com.example.myapplicationndk.utils;

import com.example.myapplicationndk.bean.Person;

import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;
import cn.bmob.v3.listener.SaveListener;

/**
 *
 * bmob 后台文档
 * http://doc.bmob.cn/data/android/index.html
 *
 */
public class BmobUtils {

    public static void insert() {
        Person p2 = new Person();
        p2.setName(GenerateString.getRandomString(5));
        p2.setAddress("北京海淀");
        p2.save(new SaveListener<String>() {
            @Override
            public void done(String objectId, BmobException e) {
                if (e == null) {
                    ToastUtils.show("添加数据成功，返回objectId为：" + objectId);

                } else {
                    ToastUtils.show("创建数据失败：" + e.getMessage());
                }
            }
        });


    }

    public static void query() {

        BmobQuery<Person> query = new BmobQuery<Person>();
        query.setLimit(8).order("-createdAt")
                .findObjects(new FindListener<Person>() {
                    @Override
                    public void done(List<Person> object, BmobException e) {
                        if (e == null) {
                            Logd.Logd(object.toString());
                        } else {
                            Logd.Logd(e.toString());
                        }
                    }
                });
    }


}
